package HLLib.base;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLLibObject;

public class HLSoundManager extends HLLibObject {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_BASE, HLClassManager_H.LIB_CLASS_BASE_SoundManager);
    }

    private static String preBackgroundMusic;

    private static HLList sounds = new HLList();

    // backgroundMusic
    public static void PreloadBackgroundMusic(HLString path) {
         if (GetSoundIndex(path) < 0) {
         sounds.Add(path);
         HLSoundManagerOld.AddSound(path, -1);
         }
    }

    public static void PlayBackgroundMusic(HLString path) {
         int index = GetSoundIndex(path);
         if (index < 0) {
         sounds.Add(path);
         HLSoundManagerOld.AddSound(path, -1);
         index = sounds.Count() - 1;
         }
         HLSoundManagerOld.play(index);
    }

    public static void PlayBackgroundMusicWithLoop(HLString path, int loop) {
         PlayBackgroundMusic(path);
    }

    public static void StopBackgroundMusic() {
         HLSoundManagerOld.stop();
    }

    public static void PauseBackgroundMusic() {
         HLSoundManagerOld.pause();
    }

    public static void RestartBackgroundMusic() {
         HLSoundManagerOld.resume();
    }

    public static boolean IsBackgroundMusicPlaying() {
        return HLSoundManagerOld.isPlaying();
    }

    public static boolean WillBackgroundMusicPlaying() {
        return HLSoundManagerOld.isPlaying();
    }

    // sound effects
    public static void PreloadEffect(HLString path) {
         if (GetSoundIndex(path) < 0) {
         sounds.Add(path);
         HLSoundManagerOld.AddSound(path, 1);
         }
    }

    public static int PlayEffect(HLString path) {
         int index = GetSoundIndex(path);
         if (index < 0) {
         sounds.Add(path);
         HLSoundManagerOld.AddSound(path, 1);
         index = sounds.Count() - 1;
         }
         HLSoundManagerOld.playEX(index, false);
        return 0;
    }

    public static int PlayEffectWithPitchPanGain(HLString path, int pitch, int pan, int gain) {
         int index = GetSoundIndex(path);
         if (index < 0) {
         sounds.Add(path);
         HLSoundManagerOld.AddSound(path, -1);
         index = sounds.Count() - 1;
         }
         HLSoundManagerOld.play(index);
        return 0;
    }

    public static void StopEffect(int id) {
         HLSoundManagerOld.stop();
    }

    public static void UnloadEffect(HLString string) {
    }

    // control
    public static void SetMute(boolean isMute) {
         if (isMute) {
         HLSoundManagerOld.setVolume(0);
         } else {
         HLSoundManagerOld.setVolume(50);
         }

    }

    // backgroundMusicVolum
    public static int GetBackgroundMusicVolume() {
        return HLSoundManagerOld.volume;
    }

    public static void SetBackgroundMusicVolume(int volume) {
         HLSoundManagerOld.setVolume(volume);
    }

    // efeectVolum
    public static int GetEffectsVolume() {
        return HLSoundManagerOld.volume;
    }

    public static void SetEffectsVolume(int volume) {
         HLSoundManagerOld.setVolume(volume);
    }

    private static int GetSoundIndex(HLString string) {
         for (int i = 0; i < sounds.Count(); i++) {
        
         HLString tmp = (HLString) sounds.GetItem(i);
         if (tmp.Equals(string)) {
         return i;
         }
         }
        return -1;
    }

}
